System and method for scheduling instructions in a multithread simd architecture with a fixed number of registers

ABSTRACT

A method and apparatus for scheduling instructions of a shader program for a graphics processing unit (GPU) with a fixed number of registers. The method and apparatus include computing, via a processing unit (PU), a liveness-based register usage across all basic blocks in the shader program, computing, via the PU, the range of numbers of waves of a plurality of registers for the shader program, assessing the impact of available post-register allocation optimizations, computing, via the PU, the scoring data based on number of waves of the plurality of registers, and computing, via the PU, the number of waves for execution for the plurality of registers.

TECHNICAL FIELD

The disclosed method and apparatus are generally directed to schedulinginstructions in multithread devices, and in particular, to schedulinginstructions in a multithread single instruction, multiple data (SIMD)architecture with a fixed number of registers.

BACKGROUND

Present solutions to scheduling instructions in a multithreaded SIMDarchitecture are generally performed on an individual basis. This meansthe basic block with the maximum number of registers sets the number ofwaves, independent of other basic blocks. If that basic block occurslate in the shader, then other preceding basic blocks cannot use theadditional registers, and a basic block that uses a lot of registerscannot chose to schedule with fewer registers at a lower level ofperformance even if such a choice is warranted based on all basicblocks.

A shader is a program that is used to produce levels of color within animage including, but not limited to, position, hue, saturation,brightness, and contrast of pixels, for example. Shaders render effectson graphics hardware.

Shaders generally utilize parallel processing across a series ofregisters. The shader programs executed on a multithreaded SIMD machine,such as a graphics processors, need to balance maximum performance for agiven shader program against maximum throughput for multiplesimultaneous executing waves. An instruction scheduler is a part of ashader compiler targeted to generate code for such a machine. Theinstruction scheduler chooses the sequence of instructions in order tomaximize performance. One tradeoff in instruction schedulers formultithreaded SIMD machines limited by a total number of registers ismaximum performance for an individual shader program, with acorresponding typically larger number of registers, versus minimumregister usage. That is, allowing maximum throughput for multiple shaderprograms by allowing more shader programs to execute simultaneously dueto a reduction in register usage. In the case of these machines, thereis a fixed number of registers that are allocated across multiple shaderprograms, so that the sum total of the registers required in allexecuting waves cannot exceed the total number of available registers onthe machine.

For these machines, there is a fixed number of registers that areallocated across multiple shader programs. This means that shaderprograms with individual waves requiring a greater number of registerscan execute fewer waves simultaneously. As memory latency for a wave ishidden in the execution of additional waves, restricting the number ofwaves by increasing the number of registers available to individualwaves can require more waiting for memory operations to finish, therebyreducing performance.

BRIEF DESCRIPTION OF THE DRAWINGS

A more detailed understanding can be had from the following description,given by way of example in conjunction with the accompanying drawingswherein:

FIG. 1 is a block diagram of an example device in which one or moredisclosed embodiments can be implemented;

FIG. 2 is an illustration of a method for scheduling instructions in amultithread SIMD architecture with a fixed number of registers;

FIG. 3 is an illustration of a multithread SIMD device with a fixednumber of registers on which the method of FIG. 2 can be performed;

FIG. 4 is an illustration of a method for determining the liveness-basedregister usage of FIG. 2;

FIG. 5 is an illustration of a method for determining the range ofnumber of waves of FIG. 2;

FIG. 6 is an illustration of a method for assessing the impact ofpost-register allocation optimizations of FIG. 2;

FIG. 7 is an illustration of a method for computing the scoring data foreach number of waves of FIG. 2; and

FIG. 8 is an illustration of a method for determining the number ofwaves for execution of FIG. 2.

DETAILED DESCRIPTION

Typically, maximum performance for an individual shader program requiresmore registers. Maximum throughput can require more waves, each usingfewer registers. Thus there is a need to improve the choice of thenumber of waves verses the number of registers for a given shaderprogram.

A system and method for scheduling instructions of a shader program fora graphics processing unit (GPU) with a fixed number of registers isdisclosed. The system and method include computing, via a processingunit (PU), a live variable analysis of the registers used by a shaderprogram, computing, via the PU, a range of waves of the analyzedregisters based on the live variable analysis of the registers,assessing, via the PU, an impact of the computed range of waves based onthe computed range of wave of the analyzed registers, computing, via thePU, a score for the assessed impact of the computed range of waves, andcomputing, via the PU, the number of waves to execute for the registersused by the shader program based on the computed score.

A system and method is disclosed for scheduling instructions of a shaderprogram for a graphics processing unit (GPU) with a fixed number ofregisters. The system and method include computing, via a processingunit (PU), a liveness-based register usage across all basic blocks forthe shader program, computing, via the PU, the range of numbers of wavesfor a plurality of registers for the shader program, assessing theimpact of available post-register allocation optimizations, computing,via the PU, the scoring data based on the number of waves, andcomputing, via the PU, the number of waves for the plurality ofregisters.

The computing a liveness-based register usage across all basic blocks inthe shader program includes computing the minimum and maximum number ofregisters of the plurality of registers estimated for the shaderprogram.

The computing the range of numbers of waves based on the plurality ofregisters for the shader program includes computing the minimum numberof waves of the plurality of registers and the maximum numbers of wavesof the plurality of registers for the shader program.

The assessing the impact of available post-register allocationoptimizations includes computing the minimum number of waves of theplurality of registers for the shader program from the computed maximumnumber of registers of the plurality of registers.

The computing of the scoring data based on number of waves of theplurality of registers includes choosing the best scheduling algorithmbased on the scores, including post-register allocation optimization andaccumulating the information with the information for the number ofwaves of the plurality of registers for all basic blocks in the shaderprogram.

The computing the number of waves of the plurality of registers includeschoosing the number of waves, based on the best score for theaccumulated data for the number of waves, and the best score for theaccumulated data with post-register allocation optimizations, andchoosing the number of registers of the plurality of registers used bythe shader program based on the number of waves chosen.

Instruction scheduling in a multithread SIMD machine is described. Thisscheduling, for example, includes an implementation for schedulinginstructions in a program for improved performance on a multithread SIMDmachine where the number of waves is limited by a fixed total number ofregisters across all waves. The instruction scheduler examines eachbasic block, and generates a schedule for that basic block by choosingthe best schedule from the results of several different schedulingparadigms. That schedule indicates the required number of registers,which in turn indicates the maximum number of waves that can executesimultaneously. If one basic block requires significantly more registersthan the other basic blocks, that basic block can limit the number ofwaves based on that one basic block.

The instruction scheduler initially walks all the basic blocks in theshader program, and applies the different scheduling paradigms. Insteadof generating a schedule for each basic block, information can begenerated for the performance for the best schedule for a range ofnumbers of waves, and then merge that performance information across allthe basic blocks in the shader program. This merged performanceinformation is then used to select the optimum number of waves, and thatin turn selects the number of registers available for each wave. Theselected register counts are then supplied as limits to the instructionscheduler to permit optimum performance for scheduling the individualbasic blocks.

FIG. 1 is a block diagram of an example device 100 in which one or moredisclosed embodiments can be implemented. The device 100 can include,for example, a computer, a gaming device, a handheld device, a set-topbox, a television, a mobile phone, or a tablet computer. The device 100includes a processor 102, a memory 104, a storage device 106, one ormore input devices 108, and one or more output devices 110. The device100 can also optionally include an input driver 112 and a displayprocessor 114. It is understood that the device 100 can includeadditional components not shown in FIG. 1.

The processor 102 can include a central processing unit (CPU), agraphics processing unit (GPU), a CPU and GPU located on the same die,or one or more processor cores, wherein each processor core can be a CPUor a GPU. Processor 102 can be a CPU, for example, and display processor114 can be a GPU that can or cannot be on the same chip as processor102, by way of non-limiting example. The memory 104 can be located onthe same die as the processor 102, or can be located separately from theprocessor 102. The memory 104 can include a volatile or non-volatilememory, for example, random access memory (RAM), dynamic RAM, or acache.

The storage device 106 can include a fixed or removable storage, forexample, a hard disk drive, a solid state drive, an optical disk, or aflash drive. The input devices 108 can include a keyboard, a keypad, atouch screen, a touch pad, a detector, a microphone, an accelerometer, agyroscope, a biometric scanner, or a network connection (e.g., awireless local area network card for transmission and/or reception ofwireless IEEE 802 signals). The output devices 110 can include adisplay, a speaker, a printer, a haptic feedback device, one or morelights, an antenna, or a network connection (e.g., a wireless local areanetwork card for transmission and/or reception of wireless IEEE 802signals).

The input driver 112 communicates with the processor 102 and the inputdevices 108, and permits the processor 102 to receive input from theinput devices 108. Input driver 112 can be hardware, software, or acombination thereof. The display processor 114 communicates with theprocessor 102 and the output devices 110, and permits the processor 102to send output to the output devices 110. It is noted that the inputdriver 112 and the display processor 114 are optional components, andthat the device 100 will operate in the same manner if the input driver112 and the display processor 114 are not present.

FIG. 2 is an illustration of a method 200 for scheduling instructions ina multithread SIMD architecture with a fixed number of registers. Method200 includes determining the liveness-based register usage at step 210,determining the range of number of waves at step 220, assessing theimpact of post-register allocation optimizations at step 230, computingthe scoring data for each number of waves at step 240, and determiningthe number of waves at step 250.

Determining the liveness-based register usage at step 210 can beperformed across the entire shader program. For example, thisdetermination can compute where non-assigned registers start to be usedand stop being used.

This determination 210 can include an analysis of each function in theshader program. This can be performed in a bottom-up walk, such thateach function is examined before all its callers are examined.Recursion, i.e. cycles in the call graph, can be allowed in makingdetermination 210.

An analysis of the variables that are live at the beginning of eachbasic block is computed within each function of the shader program. Thenwithin each basic block within the function, different schedulingalgorithms can be applied to each basic block. Information associatedwith the basic block can be determined and saved for later usage.Examples of the determined information can be any one or a combinationof the following: some or all of the number of registers required orneeded; the execution time required for different classes ofinstructions; the delay time required to wait for operations tocomplete; and other information.

Using this information for each scheduling algorithm applied to thebasic block, the minimum and maximum number of registers needed can becomputed from the number of registers required from all schedulingalgorithms, i.e. minimum registers for basic block=minimum (number ofregisters across all scheduling algorithms).

The minimum number of registers required for a function can be computedby taking the maximum value of the minimum number of registers requiredfor each basic block in the function. The maximum number of registersrequired for the function can be computed by taking the maximum value ofthe maximum number of registers required for each basic block in thefunction.

The minimum number of registers required for the shader program can becomputed by taking the maximum of the minimum number of registersrequired for each function, and incorporating the additional registersneeded to handle calling conventions.

The maximum number of registers required for the shader program can becomputed by taking the maximum of the maximum number of registersrequired for each function, and incorporating the additional registersneeded to handle calling conventions.

Determining the range of number of waves at step 220 can apply anyadditional effects to the number of required registers from step 210,such as physical register usage. This determining 220, or computing, canbe based on the computed liveness-based register usage from step 210.Determining 220 can apply the effects of register allocation on thenumber of required registers. When the number of registers is close toor over the number of registers for a specific count of waves, atrade-off can be explored by increasing the number of waves bydecreasing the number of registers used. All basic blocks in the shaderprogram are analyzed. For each basic block, the number of registers canbe computed as needed for the effects of register allocation, and thatnumber can be used to compute the number of waves available for each ofthe scheduling algorithms. The minimum number of waves for the basicblock can be computed from the minimum of the number of waves for eachscheduling algorithm, and the maximum number of waves for the basicblock can be computed from the maximum number of waves for eachscheduling algorithm. For all basic blocks in the shader program, theminimum number of waves can be computed. For all basic blocks in theshader program, the maximum number of waves can be computed.

All basic blocks in the shader program can be analyzed. For each basicblock, the number of registers can be computed as needed for the effectsof register allocation, and that number can be used to compute thenumber of waves available for each of the scheduling algorithms. Theminimum number of waves for the basic block is computed from the minimumof the number of waves for each scheduling algorithm, and the maximumnumber of waves for the basic block is computed from the maximum numberof waves for each scheduling algorithm. For all basic blocks in theshader program, the minimum number of waves is computed. For all basicblocks in the shader program, the maximum number of waves is computed.

Assessing the impact of post-register allocation optimizations at step230 can include estimating the number of registers required for thepost-register allocation optimizations based on the computed range ofnumbers of waves of the registers from step 220. This estimation isperformed for accuracy of the optimization performed later in method200.

Assessing at step 230 can include determining if there are post-registerallocation optimizations that apply. If there are, then if the minimumnumber of registers added to the additional number of registers requiredfor the post-register allocator optimizations does not exceed themaximum number of registers available to the shader program, acomputation can be made of the maximum number of waves from the minimumnumber of registers added to the additional number of registersrequired. This can then be used as the maximum number of waves.

If the maximum number of registers added to the additional number ofregisters required for the post-register allocator optimizations doesnot exceed the maximum number of registers available to the shaderprogram, a computation can be made of the minimum number of waves fromthe maximum number of registers added to the additional number ofregisters required. This can be used as the minimum number of waves.

Computing the scoring data for each number of waves at step 240 can bebased on the assessed impact of register allocation optimizations ofstep 230. Computing the scoring data 240 can include walking each basicblock in the shader program to accumulate the range of the minimum tomaximum number of waves the basic block's accumulated scoring data isexamined for each scheduling algorithm. The best of these scores foreach basic block can be accumulated over all the basic blocks in theshader program for a given number of waves. The best of these scores canbe the highest outright score, for example. The best score can also bethe highest score after accounting for biases in the outcome forexample, such biases including a preference of using more registers, orless registers, by way of example. If there is a bias toward using moreregisters, if there are two scores that are approximately the same,although the scenario with fewer registers is actually a higher score,the scenario using more registers can be selected as the best.Additional scoring data can also be accumulated based on the impact ofother optimizations that might be applied, given sufficient numbers ofregisters.

For example, after walking over the basic blocks, it can be determinedthat 3 waves provides a score of X in the performance metric and 4 wavesprovides a score of Y in the performance metric. The better one, eitherX or Y, accounting for biases in the outcome, can then be selected andeither 3 or 4 waves selected therewith.

Determining the number of waves at step 250 can rely on the accumulatedscoring information from step 240 for the entire shader program fordiffering numbers of waves, and can include the estimated impact ofother optimizations. This can include selecting the best performancemetric, for example. Accounting for preferences and the like can also beincluded in the selection. As will be described in more detail and asshown in FIG. 8 below, this scoring data is examined, and a choice ismade of the number of waves with the best accumulated score. This numberof waves is then input to the instruction scheduler, so that the bestchoice of number of waves verses performance per wave is achieved.

FIG. 3 is an illustration of a system 300 on which the method 200 ofFIG. 2 can be performed or performed in anticipation of scheduling theinstructions on system 300. System 300 can include a graphics processorcore, such as graphics processor core 330. System 300 includes aplurality of machine wave states 310, a plurality of registers 320, alsoknown as a set of available registers, and graphics processor core 330.The plurality of machine wave states 310 can provide storage forinformation or processes to run on core 330. Plurality of machine wavestates 310 can include the computer hardware devices used to storeinformation for immediate use in a computer.

Plurality of registers 320 can be fast storage, including specifichardware functions, and can be read-only or write-only, for example.Registers 320 are normally at the top of the memory hierarchy, andprovide the fastest way to access data with registers 320 being directlyencoded as part of an instruction, as defined by the instruction set,for example.

Plurality of machine wave states 310 can include a first wave in a Wave1 state 310.1, a second wave in a Wave 2 state 310.2, and a third wavein a Wave 3 state 310.3, for example. Wave states 310.1-3 can populateregisters from the plurality of registers 320. For example, wave 1 state310.1 can populate registers 320.1, wave 2 state 310.2 can populateregisters 320.2 and wave 3 state 310.3 can populate registers 320.2.When wave 1 state 310.1 is executing via core 330 register 320.1 can beactive. Similarly as wave 2 state 310.2 is executing via core 330register 320.2 can be active, and as wave 3 state 310.3 is executing viacore 330 register 320.3 can be active. In this example, the number ofwaves equals three. This is for ease of understanding and provides onlyone example. It is to be understood that any number of waves can beused. For example, some processors can employ ten waves or more.

Method 200 can be performed on system 300, by computing a liveness-basedregister 320 usage across all basic blocks of memory 310, computing therange of numbers of waves in memory 310 by loading into registers 320for shader program, assessing the impact of available post-registerallocation optimizations, computing the scoring data based on number ofwaves from registers 320; and computing the number of waves. As setforth herein, the number of waves is the number of waves that maximizesperformance for an individual shader program while providing maximumthroughput.

FIG. 4 is an illustration of a method for determining the liveness-basedregister usage as set forth in step 210 of FIG. 2. Determining theliveness-based register usage at step 210 can be performed across theentire shader program. This determination 210 can include an analysis ofeach function in the shader program at step 405. Such analysis can beperformed in a bottom-up walk, such that each function is examinedbefore all of its callers are examined. Recursion, such as repeatingcycles in the call graph, can be allowed. This recursion can allow eachfunction to be examined before all of its callers are examined, andrecursively repeating functions.

Within each function of the shader program, an analysis of whatvariables are live at the beginning of each basic block is computed atstep 410. In essence, if the variables are live at the beginning, thesevariables can, or should, be live at the end.

Then for each basic block within the function at step 415, differentscheduling algorithms can be applied to that basic block at step 425.There can be a number of scheduling algorithms, and for each one theentire basic block can be analyzed.

Information including some or all of the number of registers required orneeded can be determined, the execution time required for differentclasses of instructions, and the delay time required to wait foroperations to complete, associated with the basic block can bedetermined and saved for later usage at step 430. The number ofinstructions of different classes executed can be the same for eachblock. A heuristic algorithm can be applied to the information toprovide a range of registers based on the minimum number of registersand the maximum number of registers.

Each scheduling algorithm is completed at step 435. Using thisinformation for each scheduling algorithm applied to the block, theminimum and maximum number of registers needed can be computed from thenumber of registers required from all scheduling algorithms at step 440.The minimum registers for basic block=minimum (number of registersacross all scheduling algorithms).

$\begin{matrix}{{{minimum}\mspace{14mu} {registers}_{{basic}\mspace{14mu} {Block}}} = \left\lfloor {\bigvee_{{Scheduling}\mspace{14mu} {Algorithms}}{{number}\mspace{14mu} {of}\mspace{14mu} {registers}}} \right\rfloor} & {{Eq}.\mspace{14mu} 1} \\{{{maximum}\mspace{14mu} {registers}_{{Basic}\mspace{14mu} {block}}} = \left\lceil {\bigvee\limits_{{Scheduling}\mspace{14mu} {Algorithms}}{{number}\mspace{14mu} {of}\mspace{14mu} {registers}}} \right\rceil} & {{Eq}.\mspace{14mu} 2}\end{matrix}$

Each basic block in the function can be completed at step 445. Theminimum number of registers required for the function can be computed atstep 450. This computation can take the maximum value of the minimumnumber of registers required for each basic block in the function.

$\begin{matrix}{{{minimum}\mspace{14mu} {registers}_{function}} = \left\lceil {\bigvee\limits_{{Basic}\mspace{14mu} {Blocks}\mspace{14mu} i\; n\mspace{14mu} {Function}}{{minimum}\mspace{14mu} {registers}_{{Basic}\mspace{14mu} {Block}}}} \right\rceil} & {{Eq}.\mspace{14mu} 3}\end{matrix}$

The maximum number of registers required for the function is computed atstep 450. This computation can take the maximum value of the maximumnumber of registers required for each basic block in the function.

$\begin{matrix}{{{maximum}\mspace{14mu} {registers}_{function}} = \left\lceil {\bigvee\limits_{{Basic}\mspace{14mu} {Blocks}\mspace{14mu} i\; n\mspace{14mu} {Function}}{{maximum}\mspace{14mu} {registers}_{{Basic}\mspace{14mu} {Block}}}} \right\rceil} & {{Eq}.\mspace{14mu} 4}\end{matrix}$

All functions in the shader program can be completed at step 455. Theminimum number of registers required for the shader program can becomputed in step 460. The minimum number of registers can be computed bytaking the maximum of the minimum number of registers required for eachfunction, and incorporating the additional registers needed to handlecalling conventions:

$\begin{matrix}{{{minimum}\mspace{14mu} {registers}_{{Shader}\mspace{14mu} {Program}}} = \left\lceil {{\bigvee\limits_{{Functions}\mspace{14mu} i\; n\mspace{14mu} {Shader}\mspace{14mu} {Program}}{{minimum}\mspace{14mu} {registers}_{Function}}} + {registers}_{{calling}\mspace{14mu} {conventions}}} \right\rceil} & {{Eq}.\mspace{14mu} 5}\end{matrix}$

The maximum number of registers required for the shader program can becomputed in step 460. The maximum number of registers can be computed bytaking the maximum of the maximum number of registers required for eachfunction, and incorporating the additional registers needed to handlecalling conventions:

$\begin{matrix}{{{maximum}\mspace{14mu} {registers}_{{Shader}\mspace{14mu} {Program}}} = \left\lceil {{\bigvee\limits_{{Functions}\mspace{14mu} i\; n\mspace{14mu} {Shader}\mspace{14mu} {Program}}{{maximum}\mspace{14mu} {registers}_{Function}}} + {registers}_{{calling}\mspace{14mu} {conventions}}} \right\rceil} & {{Eq}.\mspace{14mu} 6}\end{matrix}$

FIG. 5 is an illustration of a method for determining the range ofnumber of waves as set forth in step 220 of FIG. 2. As set forth above,determining the range of number of waves at step 220 can apply anyadditional effects to the number of required registers from step 210,such as physical register usage, for example.

Step 220 can include computing the minimum and maximum number ofregisters available for the shader program by incorporating estimatedeffects of register allocation at step 510. At step 520, the number ofregisters can be biased near thresholds between the numbers of waves toprefer higher number of waves, for example. A computation over alladjustments for the effects of register allocation of the shader programcan be performed at step 530. Determining 220 can apply the effects ofregister allocation on the number of required registers. Then when thenumber of registers is close to or over the number of registers for aspecific count of waves, a trade-off can be explored by increasing thenumber of waves by decreasing the number of registers used.

At step 535 a walk-through of all basic blocks in the shader program canbe performed. This can include applying all scheduling algorithms atstep 545. A computation of the number of waves from the number ofrequired registers for each scheduling algorithm using adjustments forregister allocation can be performed at step 550. All blocks in theshader program are analyzed. For each block, the number of registers canbe computed as needed for the effects of register allocation, and thatnumber can be used to compute the number of waves available for each ofthe scheduling algorithms. The minimum number of waves for the block canbe computed from the minimum of the number of waves for each schedulingalgorithm:

minimum waves_(basic Block)=└V_(Scheduling Algorithms)number of waves┘  Eq. 7

The maximum number of waves for the block can be computed from themaximum number of waves for each scheduling algorithm:

$\begin{matrix}{{{maximum}\mspace{14mu} {waves}_{{Basic}\mspace{14mu} {block}}} = \left\lceil {\bigvee\limits_{{Scheduling}\mspace{20mu} {Algorithms}}{{number}\mspace{14mu} {of}\mspace{14mu} {waves}}} \right\rceil} & {{Eq}.\mspace{14mu} 8}\end{matrix}$

The completion of the walking of all scheduling algorithms can occur atstep 555.

A computation of the minimum and maximum number of waves for each basicblock based on the minimum and maximum registers for each schedulingalgorithm can be performed at step 560. The completion of theapplication of all basic blocks in the shader program can occur at step565.

The minimum number of waves for the shader program can be computed atstep 570. This minimum can be computed by taking the maximum of theminimum number of waves for each scheduling algorithm. For all basicblocks in the shader program, the minimum number of waves can becomputed by:

minimum waves_(Shader Program)=└V_(Basic Blocks)minimum waves┘   Eq. 9

The maximum number of waves for the shader program can be computed atstep 580. This maximum can be computed by taking the maximum of themaximum number of waves for each scheduling algorithm. For all basicblocks in the shader program, the maximum number of waves can becomputed by:

minimum waves_(Shader Program)=└V_(Basic Blocks)maximum waves┘   Eq. 10

FIG. 6 is an illustration of a method for assessing the impact ofpost-register allocation optimizations as set forth in step 230 of FIG.2. Assessing the impact of post-register allocation optimizations atstep 230 can include estimating the number of registers required for thepost-register allocation optimizations at step 610. Assessing at step230 can include determining if there are post-register allocationoptimizations that apply at step 620. If there are post-registerallocation optimizations that apply, a determination if the minimumregisters and additional registers fit in the registers available can bemade at step 630. If the registers are a fit in step 630, a computationof the maximum number of waves for the shader program from the previousminimum computed number of registers and additional registers can beperformed at step 640. This can be used as the maximum number of waves.

If the maximum number of registers added to the additional number ofregisters required for the post-register allocation optimization doesnot exceed the maximum number of registers available to the shaderprogram at step 650, a computation of the minimum number of waves forthe shader program from the computed maximum number of registers addedto the additional number of registers required can be performed at step660. This value is now used as the minimum number of waves.

If a determination is made that there are not post-register allocationoptimizations that apply at step 620, if the registers do not fit instep 630, or if the maximum number of registers added to the additionalnumber of registers required for the post-register allocationoptimizations does exceed the maximum number of registers available tothe shader program at step 650, then an output of the original minimumnumbers of waves can occur at step 670.

FIG. 7 is an illustration of a method for computing the scoring data foreach number of waves as set forth in step 240 of FIG. 2. The scoringdata for each number of waves at step 240 can be computed by walkingeach block in the shader program to accumulate the range of the minimumto maximum number of waves of the block's accumulated scoring data asexamined for each scheduling algorithm.

Computing the scoring data for each number of waves at step 240 caninclude the underlying steps to take the number of waves and walkthrough the blocks and scheduling algorithms to output a score for each.This computation can include initializing aggregate scoring informationfor the range of waves that can be examined at step 710. Then walking ofall basic blocks in the shader program can begin at step 715. Thiswalking in step 715 can include walking overall numbers of waves in thespecified range at step 725. This can include computing the number ofregisters available for the number of waves at step 730.

Walking through all of the scheduling algorithms can occur at step 735.This can include computing the score based on the estimated performancefor the basic block using the saved scheduling information at step 740.

Step 745 can include a query to determine if there is a post-registerallocation optimization and determine if sufficient registers areavailable. If step 745 is determined in the affirmative, i.e.,sufficient registers exist, step 750 can compute a score for the numberof waves based on the estimated performance for the basic block usingthe saved scheduling information and applying the post-registerallocation optimization.

If step 745 is determined in the negative, i.e., sufficient registersare not available, or if step 750 has been completed, step 755 caninclude ending the walk of all scheduling algorithms.

The best scheduling algorithm can be chosen at step 760 based on thescore with and without the post-register allocation optimization. Thesescores can be accumulated with the information for the same number ofwaves for all blocks. Step 765 can include ending the walk of all basicblocks in the shader program.

FIG. 8 is an illustration of a method for determining the number ofwaves as set forth in step 250 of FIG. 2. Determining the number ofwaves of step 250 can rely on the accumulated scoring information forthe entire shader program for differing numbers of waves, and canincorporate the estimated impact of other optimizations. Determining thenumber of waves of step 250 can include a walk over all numbers of wavein the specified range at step 805. A score can be computed for thenumber of waves based on the accumulated data at step 810 for the shaderprogram generated in step 240 described in more detail above withrespect to FIG. 7. Step 815 can include a query to determine if there isa post-register allocation optimization and determine if sufficientregisters are available. If step 815 is determined in the affirmative,i.e., sufficient registers exist, step 820 can compute a score for thenumber of waves based on the accumulated data incorporating thepost-register allocation optimizations for the shader program generatedin step 240 described in more detail above with respect to FIG. 7.

If step 815 is determined in the negative, i.e., sufficient registersare not available, or if step 820 has been completed, step 825 caninclude ending the walk of all scheduling algorithms. The number ofwaves can be chosen at step 830 based on the best score for theaccumulated data for the number of waves and the best score for theaccumulated data with post-register allocation optimizations. Thischoice can include a bias towards more waves, for example, because of anunderlying preference to include more waves. So if scores are similar,the choice can select more waves even if that score is a slightly lowerscore. Step 840 can include computing the number of registers used bythe shader program based on the number of waves chosen in step 830.

It should be understood that many variations are possible based on thedisclosure herein. Although features and elements are described above inparticular combinations, each feature or element can be used alonewithout the other features and elements or in various combinations withor without other features and elements.

The methods provided can be implemented in a general purpose computer, aprocessor, or a processor core. Suitable processors include, by way ofexample, a general purpose processor, a special purpose processor, aconventional processor, a digital signal processor (DSP), a plurality ofmicroprocessors, one or more microprocessors in association with a DSPcore, a controller, a microcontroller, Application Specific IntegratedCircuits (ASICs), Field Programmable Gate Arrays (FPGAs) circuits, anyother type of integrated circuit (IC), and/or a state machine. Suchprocessors can be manufactured by configuring a manufacturing processusing the results of processed hardware description language (HDL)instructions and other intermediary data including netlists (suchinstructions capable of being stored on a computer readable media). Theresults of such processing can be maskworks that are then used in asemiconductor manufacturing process to manufacture a processor whichimplements aspects of the embodiments.

The methods or flow charts provided herein can be implemented in acomputer program, software, or firmware incorporated in a non-transitorycomputer-readable storage medium for execution by a general purposecomputer or a processor. Examples of non-transitory computer-readablestorage mediums include a read only memory (ROM), a random access memory(RAM), a register, cache memory, semiconductor memory devices, magneticmedia such as internal hard disks and removable disks, magneto-opticalmedia, and optical media such as CD-ROM disks, and digital versatiledisks (DVDs).

What is claimed is:
 1. A method for scheduling instructions of a shaderprogram for a graphics processing unit (GPU) with a fixed number ofregisters, the method comprising: computing, via a processing unit (PU),a live variable analysis of the registers used by a shader program;computing, via the PU, a range of waves of the analyzed registers basedon the live variable analysis of the registers; assessing, via the PU,an impact of the computed range of waves based on the computed range ofwave of the analyzed registers; computing, via the PU, a score for theassessed impact of the computed range of waves; and computing, via thePU, the number of waves to execute for the registers used by the shaderprogram based on the computed score.
 2. The method of claim 1, whereinthe live variable analysis of the registers used by a shader programincludes a liveness-based register usage across all basic blocks in theshader program.
 3. The method of claim 2, wherein the computing aliveness-based register usage across all basic blocks in the shaderprogram includes computing a minimum and maximum number of registers ofthe plurality of registers estimated for the shader program.
 4. Themethod of claim 1, wherein the range of waves of the analyzed registersincludes a range of numbers of waves of a plurality of registers for theshader program based on the live variable analysis of the registers usedby a shader program.
 5. The method of claim 4, wherein the computing therange of numbers of waves of the plurality of registers for the shaderprogram includes computing a minimum number of waves of the plurality ofregisters and a maximum numbers of waves of the plurality of registersfor the shader program.
 6. The method of claim 1, wherein the impact ofthe computed range of waves includes an impact of availablepost-register allocation optimizations based on the range of waves ofthe analyzed registers.
 7. The method of claim 6, wherein the assessingthe impact of available post-register allocation optimizations includescomputing a minimum number of waves of the plurality of registers forthe shader program from the computed maximum number of registers of theplurality of registers.
 8. The method of claim 1, wherein the score forthe assessed impact of the computed range of waves includes a scoringdata based on the assessed impact of available post-register allocationoptimizations.
 9. The method of claim 8, wherein the computing thescoring data based on number of waves of the plurality of registersincludes choosing a best scheduling algorithm based on the scoresincluding post-register allocation optimization and accumulate theinformation with the information for the number of waves of theplurality of registers for all blocks in the shader program.
 10. Themethod of claim 1, wherein the number of waves to execute for theregisters used by the shader program based on the computed scoreincludes a number of waves for the plurality of registers based on thecomputed scoring data.
 11. The method of claim 10, wherein the computingthe number of waves of the plurality of registers includes choosing thenumber of waves, based on a best score for the accumulated data for thenumber of waves, and the best score for the accumulated data withpost-register allocation optimizations, and choosing the number ofregisters of the plurality of registers used by the shader program basedon the number of waves chosen.
 12. The method of claim 1, wherein the PUis one of a central processing unit (CPU) and a GPU.
 13. A graphicsprocessor with optimized scheduling of instructions of a shader program,the scheduling of instructions optimized by: computing, via a processingunit (PU), a live variable analysis of the registers used by a shaderprogram; computing, via the PU, a range of waves of the analyzedregisters based on the computed live variable analysis; assessing, viathe PU, an impact of the computed range of waves based on the computedrange of numbers of waves of the plurality of registers; computing, viathe PU, a score for the assessed impact of the computed range of waves;and computing, via the PU, the number of waves to execute for theregisters used by the shader program based on the computed score. 14.The graphics processor of claim 13, wherein the computing a livevariable analysis of the registers used by a shader program includescomputing a minimum and maximum number of registers of the plurality ofregisters estimated for the shader program.
 15. The graphics processorof claim 13, wherein the a range of waves of the analyzed registersincludes computing a minimum number of waves of the plurality ofregisters and a maximum numbers of waves of the plurality of registersfor the shader program.
 16. The graphics processor of claim 13, whereinthe assessing the impact of the computed range of waves includescomputing a minimum number of waves of the plurality of registers forthe shader program from the computed maximum number of registers of theplurality of registers.
 17. The graphics processor of claim 13, whereinthe computing a score for the assessed impact of the computed range ofwaves includes choosing a best scheduling algorithm based on the scoresincluding post-register allocation optimization and accumulate theinformation with the information for the number of waves of theplurality of registers for all basic blocks in the shader program. 18.The graphics processor of claim 13, wherein the computing the number ofwaves to execute for the registers used by the shader program based onthe computed score includes choosing the number of waves, based on abest score for the accumulated data for the number of waves, and thebest score for the accumulated data with post-register allocationoptimizations, and choosing the number of registers of the plurality ofregisters used by the shader program based on the number of waveschosen.
 19. The graphics processor of claim 13, wherein the PU is one ofa central processing unit (CPU) and a GPU.